package ch.bfh.abhmcm.SoftwareEngineeringAndDesign.view.mainframe.exportRFCPanel.exportRFCPanelSubs;

import java.awt.BorderLayout;
import java.awt.FlowLayout;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JPanel;
import javax.swing.JProgressBar;

import ch.bfh.abhmcm.SoftwareEngineeringAndDesign.controller.exportRFC.ExportDialogThread;
import ch.bfh.abhmcm.SoftwareEngineeringAndDesign.view.mainframe.exportRFCPanel.ExportRFCPanel;
import ch.bfh.abhmcm.SoftwareEngineeringAndDesign.view.mainframe.exportRFCPanel.listeners.CancelExportButtonListener;

public class ExportProgressbarDialog extends JDialog{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private JProgressBar progressBar;
	private JButton cancelButton;
	private ExportDialogThread dialogThread;
	private ExportRFCPanel exportRFCPanel;
	
	public ExportProgressbarDialog(ExportRFCPanel exportRFCPanel){
		this.exportRFCPanel = exportRFCPanel;
		
		this.setSize(300, 90);
		this.setLayout(new BorderLayout());
		this.setTitle("RFC werden Exportiert");
		this.setName("RFC werden Exportiert");
		
		int max = exportRFCPanel.getListPanel().getDisplayTable().getRowCount();
		this.progressBar  = new JProgressBar(0, max);
		
		this.cancelButton = new JButton("Abbrechen");
		this.cancelButton.addActionListener(new CancelExportButtonListener(this));
		
		this.add(new LayoutHelper(), BorderLayout.CENTER);
		this.add(new LayoutHelper2(), BorderLayout.SOUTH);
		
		this.dialogThread = new ExportDialogThread(exportRFCPanel,this, progressBar);
		this.dialogThread.start();
		
		this.setVisible(true);
	}
	
	public ExportRFCPanel getExportRFCPanel() {
		return exportRFCPanel;
	}

	private class LayoutHelper extends JPanel{
		
		/**
		 * 
		 */
		private static final long serialVersionUID = 1L;

		private LayoutHelper(){
			this.setLayout(new BorderLayout());
			this.add(progressBar,BorderLayout.NORTH);
		}
	}
	
	private class LayoutHelper2 extends JPanel{
		
		/**
		 * 
		 */
		private static final long serialVersionUID = 1L;

		private LayoutHelper2(){
			this.setLayout(new FlowLayout());
			this.add(cancelButton);
		}
	}
}
